package com.we823.project.controller.report;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.we823.project.controller.AbstractBaseController;
import com.we823.project.core.web.WebConstants;
import com.we823.project.model.repo.MaterialStockModel;
import com.we823.project.repository.service.repo.MaterialStockService;

@Controller
@RequestMapping(WebConstants.REPORT_PRODUCT)
public class ProductStockController extends AbstractBaseController<MaterialStockModel> {
	
	private MaterialStockService materialStockService;
	
	private static String baseUrl = WebConstants.REPORT_PRODUCT_TEMPLATE;
	
	@Autowired
	public ProductStockController(MaterialStockService materialStockService) {
		super(materialStockService);
		super.baseUrl = baseUrl;
		this.materialStockService = materialStockService;
	}

	@Override
	public Page<MaterialStockModel> getData(PageRequest pageRequest,
			HttpServletRequest request, org.springframework.ui.Model model,
			boolean pageable) {
		Page<MaterialStockModel> stockPage = null;
		if(pageable) {
			stockPage = materialStockService.findAll(pageRequest);
		}else {
			stockPage = new PageImpl<MaterialStockModel>(materialStockService.findAll());
		}
		return stockPage;
	}
	
	public MaterialStockService getMaterialStockService() {
		return materialStockService;
	}

	public void setMaterialStockService(MaterialStockService materialStockService) {
		this.materialStockService = materialStockService;
	}
	
}
